# encoding: utf-8
from flask_marshmallow import base_fields
from app.modules.common.parameters import BaseParameters,Parameters

"""
操作工程时使用
"""


class ProjectBaseParameters(BaseParameters):
    project_name = base_fields.String(
        description = "工程名称",
        required = True,
    )


class ProjectListBaseParameters(BaseParameters):
    integration_id = base_fields.String(
        description = "集成计划id",
        required = False,
        missing = None
    )


# class UpdateProjectStatusParameters(ProjectBaseParameters):
#     status = base_fields.String(
#         description = "工程状态",
#         required = True,
#     )


class UpdateProjectStatusParameters(BaseParameters):
    project_name = base_fields.String(
        description = "工程名",
        required = True,
    )
    new_status = base_fields.String(
        description = "新状态",
        enum = ['PRO_NOT_CREATE', 'PRO_CREATED', 'PRO_CREATE_ERROR', 'PRO_DEVELOPING', 'PRO_TESTING', 'PRO_MERGED',
                'TO_INTEGRATION', 'INTEGRATIONING', 'BE_CANCEL', 'HAND_OVER', 'ONLINE'],
        required = True,
    )


class UpdateProjectEditionParameters(BaseParameters):
    plan_id = base_fields.String(
        description = "项目id",
        required = True,
    )
    project_name = base_fields.String(
        description = "工程名",
        required = True,
    )
    edition_num = base_fields.String(
        description = "版本号",
        required = True,
    )
    type = base_fields.String(
        description = "操作类型，包括提测、取消提测、测试、取消测试、转测、取消转测、可以集成、不可以集成、集成测试、取消集成测试、交付运维、取消交付、上线",
        enum = ['to_test', 'cancel_to_test', 'test', 'cancel_test', 'to_integration', 'cancel_to_integration',
                'can_integration', 'can_not_integration', 'integration', 'cancel_integration', 'hand_over',
                'cancel_hand_over', 'online'],
        required = True,
    )


class ProjectOnlineVersionParameters(BaseParameters):
    project_list = base_fields.String(
        description = "主干工程名称列表",
        required = True,
    )


class UpdateProjectDeployUserParameters(BaseParameters):
    integration_id = base_fields.String(
        description = "集成计划id",
        required = True,
    )
    trunk_name = base_fields.String(
        description = "主干工程名称",
        required = True,
    )
    zone_code = base_fields.String(
        description = "区域代号",
        required = True,
    )
    account = base_fields.String(
        description = "用户账号",
        required = True,
    )
    realname = base_fields.String(
        description = "用户姓名",
        required = True,
    )


class GetPHORecordListParameters(ProjectBaseParameters):
    type = base_fields.String(
        description = "交付记录类型",
        enum = ["TEST", "INTEGRATION"],
        required = True,
    )
    edition_num = base_fields.String(
        description = "版本号",
        required = False,
        missing = None
    )
    start_date = base_fields.DateTime(
        required = False,
        missing = None
    )
    end_date = base_fields.DateTime(
        required = False,
        missing = None
    )


class SavePHORecordParameters(GetPHORecordListParameters):
    edition_num = base_fields.String(
        description = "版本号",
        required = True,
    )
    config_desc = base_fields.String(
        description = "配置文件描述",
        required = False,
        missing = None
    )
    sql_desc = base_fields.String(
        description = "sql描述",
        required = False,
        missing = None
    )
    other_desc = base_fields.String(
        description = "其他说明",
        required = False,
        missing = None
    )
    is_handle_bug = base_fields.String(
        required = False,
        missing = '1'
    )


class UpdatePHORecordStatusParameters(BaseParameters):
    id = base_fields.String(
        description = "记录id",
        required = True,
    )
    is_can_integration = base_fields.String(
        description = "是否批准集成  0 是 1 否",
        enum = ["0", "1"],
        required = False,
        missing = None
    )
    is_integration_test = base_fields.String(
        description = "是否集成测试 0 是 1 否",
        enum = ["0", "1"],
        required = False,
        missing = None
    )
    is_function_test = base_fields.String(
        description = "是否功能测试  0 是 1 否",
        enum = ["0", "1"],
        required = False,
        missing = None
    )


class MergeProToTrunkParameters(BaseParameters):
    integration_id = base_fields.String(
        description = "集成计划id",
        required = True,
    )
    project_name = base_fields.String(
        description = "工程名称",
        required = True,
    )
    type = base_fields.String(
        description = "代码来源,svn为从svn上复制,local为使用本地备份",
        required = True,
        enum = ["svn", "local"],
    )


class GetProMergeRecordListParameters(BaseParameters):
    project_name = base_fields.String(
        description = "工程名称",
        required = False,
        missing = None
    )
    integration_id = base_fields.String(
        description = "集成计划id",
        required = False,
        missing = None
    )

class HandleProjectSvnParameters(Parameters):
    trunk_name = base_fields.String(
        description = "主干工程名称",
        required = True,
    )
    svn_url = base_fields.String(
        description = "主干工程对应的svn地址",
        required = False,
        missing = None
    )
